package com.ywh.log;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 日志分析工具
 * 
 * @author jiangkunpeng
 * @since 2011-4-7
 * @version 1.0
 */
public class LogTool {

	public static void main(String[] args) {
		if (args.length < 3) {
			System.out.println("输入正确的参数 ： 月份  最小值  最大值  输出文件名");
			return;
		}
		String startname = "log/2011-0";
		int month = Integer.parseInt(args[0]);
		int min = Integer.parseInt(args[1]);
		int max = Integer.parseInt(args[2]);
		String endname = "StorageItem.log";
		String endname2 = "tradeInfo.log";
		String out = args[3];
		PrintWriter pw = null;
		try {
			pw = new PrintWriter(new FileWriter(out, true));
		} catch (IOException e) {
			e.printStackTrace();
		}
		for (; min <= max; min++) {
			String StorageItem = null;
			String tradeInfo = null;
			if (min < 10) {
				StorageItem = startname + month + "-" + "0" + min + endname;
				tradeInfo = startname + month + "-" + "0" + min + endname2;
			} else {
				StorageItem = startname + month + "-" + min + endname;
				tradeInfo = startname + month + "-" + min + endname2;
			}
			System.out.println("开始分析" + tradeInfo + "和" + StorageItem);
			StorgeAndTrade sat = new StorgeAndTrade();
			try {
				sat.readtradeLog(tradeInfo);
				sat.readstorgeLog(StorageItem);
				sat.analyse(pw);
				System.out.println(tradeInfo + "和" + StorageItem + "分析结束");
			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
		}
		pw.println("==============================================\n\n");
		if (pw != null)
			pw.close();
		System.out.println("结果已输出到文件：" + out);
		System.out.println("分析结束");
	}

}
